import random

def read_and_shuffle_write(input_file_path, output_file_path):
    """
    从指定文件中读取全部数据，按照行的内容随机排序，然后写入到新的文件中。

    :param input_file_path: 输入文件的路径
    :param output_file_path: 输出文件的路径
    """
    try:
        # 读取文件内容
        with open(input_file_path, 'r', encoding='utf-8') as infile:
            lines = infile.readlines()

        # 随机排序
        random.shuffle(lines)

        # 写入到新文件
        with open(output_file_path, 'w', encoding='utf-8') as outfile:
            outfile.writelines(lines)

        print(f"文件已成功随机排序并写入到 {output_file_path}")
    except FileNotFoundError:
        print(f"错误：文件 '{input_file_path}' 未找到。")
    except Exception as e:
        print(f"发生错误：{str(e)}")

# 示例用法
if __name__ == "__main__":
    input_file_path = 'test1'  # 输入文件路径
    output_file_path = 'test2'  # 输出文件路径
    read_and_shuffle_write(input_file_path, output_file_path)
